/*
* 1videoConference -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, Adiance Technologies Pvt. Ltd.
*
* Hardik Sanghvi <hardik.sanghvi @adiance.com>
*
* See http://www.1videoconference.org for more information about
* the 1videoConference project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;

using _videoConference.BAL;

namespace _videoConference
{
    public partial class UploadModuleControl : System.Windows.Controls.UserControl,IDisposable
    {
        
        ZipUnzip z = new ZipUnzip();
        private bool disposed = false;

        public UploadModuleControl()
        {
            InitializeComponent();
            
            btnUpload.Click += new RoutedEventHandler(btnUpload_Click);
            btnBrowse.Click += new RoutedEventHandler(btnBrowse_Click);
            btnCancel.Click += new RoutedEventHandler(btnCancel_Click);
        }

        void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            txtModuleName.Text = "";
            txtPathName.Text = "";
            ((Canvas)((Grid)((InkCanvas)((InkCanvas)this.Parent).Parent).Parent).FindName("cnvMain")).IsEnabled = true;
            ((Menu)((Grid)((InkCanvas)((InkCanvas)this.Parent).Parent).Parent).FindName("mnu")).IsEnabled = true;
            ((InkCanvas)this.Parent).Children.Remove(this);
        }

        void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Zip Files|*.zip";
            ofd.ShowDialog();
            txtPathName.Text = ofd.FileName;
        }

        void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            string currentpath = z.uploadfile(txtPathName.Text, txtModuleName.Text);
            if (currentpath != "")
            {
                UserInfo.fuc.uploadfile(currentpath, txtModuleName.Text);
                ((Canvas)((Grid)((InkCanvas)((InkCanvas)this.Parent).Parent).Parent).FindName("cnvMain")).IsEnabled = true;
                ((Menu)((Grid)((InkCanvas)((InkCanvas)this.Parent).Parent).Parent).FindName("mnu")).IsEnabled = true;
                ((InkCanvas)this.Parent).Children.Remove(this);
            }
            else
            {
                MessageBox.Show("Error while updating database");
            }
            txtPathName.Text = "";
            txtModuleName.Text = "";
        }

         public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);    
        }

         private void Dispose(bool disposing)
        {
            if(!this.disposed)
            {
                if(disposing)
                { 
                   
                }        
                disposed = true;
            }
        }

        ~UploadModuleControl()
        {
            Dispose(false);
        }


    }
}